package com.castday2.castday2.test.constructor_cast;

/**
 * @Author : 徐闯 mpcast
 * @Date : 2021-05-24 13:05:28
 * @Description : 建造者模式案例
 **/
public class Student {
    private int age;
    private String name;
    private String sex;

    public Student(Builder builder){
        this.age = builder.age;
        this.name = builder.name;
        this.sex = builder.sex;
    }

    static class Builder{
        private int age;
        private String name;
        private String sex;

        public int getAge() {
            return age;
        }

        public Builder setAge(int age) {
            this.age = age;
            return this;
        }

        public String getName() {
            return name;
        }

        public Builder setName(String name) {
            this.name = name;
            return this;
        }

        public String getSex() {
            return sex;
        }

        public Builder setSex(String sex) {
            this.sex = sex;
            return this;
        }
        public Student build(){
            return new Student(this);
        }
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                '}';
    }
}
